#ifndef SERIAL_PORT_H
#define SERIAL_PORT_H

#include <QObject>
#include <QSerialPort>
#include <QIODevice>
#include <QSerialPortInfo>
#include <QList>
#include <QMap>

class SerialPort : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString                  uartName    MEMBER m_uartName)
    Q_PROPERTY(QSerialPort::BaudRate    baud        MEMBER m_baud)
    Q_PROPERTY(QSerialPort::Parity      parity      MEMBER m_parity)
    Q_PROPERTY(QSerialPort::DataBits    dataBits    MEMBER m_dataBits)
    Q_PROPERTY(QSerialPort::StopBits    stopBits    MEMBER m_stopBits)
    Q_PROPERTY(QString                  error       MEMBER m_error)

    Q_ENUMS(QSerialPort::BaudRate)
    Q_ENUMS(QSerialPort::Parity)
    Q_ENUMS(QSerialPort::DataBits)
    Q_ENUMS(QSerialPort::StopBits)


public:
    explicit SerialPort(QObject *parent = nullptr);
    ~SerialPort();

protected:


signals:
    void opened();
    void openFailed();
    void closed();

public slots:
    bool open();
    void close();

private:
    QSerialPort* m_uart;

    QString m_uartName;
    QSerialPort::BaudRate m_baud;
    QSerialPort::Parity m_parity;
    QSerialPort::DataBits m_dataBits;
    QSerialPort::StopBits m_stopBits;
    QString m_error;
};

#endif // SERIAL_PORT_H
